package leetcode_401_500;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class LeeCode_448 {
    public static void main(String[] args) {
        System.out.println(findDisappearedNumbers(new int[]{4, 3, 2, 7, 8, 2, 3, 1}));
    }

    private static List<Integer> findDisappearedNumbers(int[] nums) {
        int n = nums.length;
        List<Integer> ans = new ArrayList<>();
        Arrays.sort(nums);
        int i = 1;
        for (int num : nums) {
            if (num == i){
                i++;
                continue;
            }
            if (num > i){
                while (i < num) {
                    ans.add(i);
                    i++;
                }
                i++;
            }
        }
        while (i <= n) {
            ans.add(i);
            i++;
        }
        return ans;
    }
}
